var map = null;
Hynetic.maps.loadJScript('5sWrhc0VSrd9S5CXgbDX2xLrXkaxhKAv');
//从这里开始就是百度地图的回调函数,这是自己写的
hyneticMap = function () {
    map = new BMap.Map("device_position", {enableMapClick: false, minZoom: 1, maxZoom: 24});            // 创建Map实例
    map.setMapStyle({style: 'googlelite'});
    map.centerAndZoom(new BMap.Point(116.284471, 39.998614), 14);// 创建点坐标
    map.enableScrollWheelZoom(true); //启用滚轮放大缩小，默认禁用
    map.enableDragging();    //启用地图惯性拖拽，默认禁用,
};

$(function () {
    $('.weui-navbar__item').on('click', function () {
        var url = $(this).attr('to-url');
        $(this).addClass('weui-bar__item_on').siblings('.weui-bar__item_on').removeClass('weui-bar__item_on');
        $(jQuery(this).attr("href")).show().siblings('.weui-tab__content').hide();
        if (url === 'test_process') {

        } else if (url === 'device_position') {
            // getDeviceByPosition(1, 1);
        } else if (url === 'real_time_working') {
            // getRealTimeWorking(1, 1);
        }
    });
    // getTesterByDevice(1, 1, 1, 1);
});


function getRealTimeWorking(tenantId, boxId) {
    $.ajax({
        type: "get",
        url: common.getRealTimeWorking,
        data: {"tenantId": tenantId, "boxId": boxId},
        success: function (result) {
            //这里是解析的json数据   直接返回data
            var data = result;
            var str = '';
            if (data.code == 0) {
                var list = data.data;
                for (var i = 0; i < list.length; i++) {
                    var o = list[i];
                    str += '<div class="h-td">' + o.attributeName + '</div>';
                    str += '<div class="h-value">' + o.attributeValue + '</div>';
                    str += '<div class="h-hr"></div>';
                }
            } else {
                str = '暂无数据';
                common.showMsgTips(data.msg);
            }
            $('#sg-working-body').html(str);
            //数据格式
            //[{"code":0,"data":[{"attributeName":"温度","attributeValue":"0"},{"attributeName":"温度","attributeValue":"0"}],"msg":""}]
        }
    });
}

function getDeviceByPosition(tenantId, boxId) {
    $.ajax({
        type: "get",
        url: common.getDeviceByPositionUrl,
        data: {"tenantId": tenantId, "boxId": boxId},
        success: function (result) {
            //这里是解析的json数据   直接返回data
            var data = result;
            var str = '';
            if (data.code == 0) {
                //转换成map用的json格式
                var list = data.data;
                var mapList = [];
                for (var i = 0; i < list.length; i++) {
                    var obj = {};
                    obj.id = i;
                    obj.title = "";
                    obj.longitude = list[i].longitude;
                    obj.latitude = list[i].latitude;
                    mapList.push(obj);
                }
                Hynetic.maps.createMapMark(mapList, null, '../../common/images/sg-marker.png', false);
            } else {
                common.showMsgTips(data.msg);
            }
            console.log(mapList);
            //数据格式
            //[{"code":0,"data":[{"attributeName":"温度","attributeValue":"0"},{"attributeName":"温度","attributeValue":"0"}],"msg":""}]
        }
    });
}

